package main

import (
	goods2 "Learngo/doc/2_2_interface/goods"
	goodimpl2 "Learngo/doc/2_2_interface/goods/goodimpl"
	"fmt"
)

func main() {
	// 构建两个商品
	iPhone := goodimpl2.Phone{
		Name:     "iPhone",
		Quantity: 1,
		Price:    8000,
	}
	earPhones := goodimpl2.FreeGift{
		Name:     "耳机",
		Quantity: 1,
		Price:    0,
	}

	// 构建一个商品购物车
	goods := []goods2.Goods{iPhone, earPhones}
	allPrice := calculateAllPrice(goods)
	fmt.Printf("该订单总共需要支付%d元", allPrice)
}

// 定义一个方法来计算购物车中的金额
func calculateAllPrice(goods []goods2.Goods) int {
	var allPrice int
	for _, good := range goods {
		fmt.Println(good.OrderInfo())
		allPrice += good.SettleAccount()
	}
	return allPrice
}
